python list insert out of range

40

names = ["Kelly", "Nelly", "Jimmy", "Lenny"]

for name in range(5):
    print(names[name])
    
#output

#Kelly
#Nelly
#Jimmy
#Lenny
#Traceback (most recent call last):
#  File "/Users/dionysialemonaki/python_articles/demo.py", line 7, in <module>
#   print(names[name])
#IndexError: list index out of range

Comments

Submit
0 Comments